{include file='head'/}
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label required">旧密码</label>
                <div class="layui-input-block">
                    <input type="password" id="oldpwd" name="oldpwd" lay-verify="required" autocomplete="off" placeholder="请输入旧密码" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">新密码</label>
                <div class="layui-input-block">
                    <input type="password" id="newpwd" name="newpwd" lay-verify="required|pwd" autocomplete="off" placeholder="请输入新密码" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">确定密码</label>
                <div class="layui-input-block">
                    <input type="password" id="confirm" name="confirm" lay-verify="required|confirmPass" autocomplete="off" placeholder="请再次输入密码" class="layui-input">
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="admin-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

{include file='footer'/}
<script>
  layui.use(['form', 'jquery'], function () {
    let form = layui.form;
    let $ = layui.jquery;
    form.verify({
      pwd: [
        /^[\S]{6,15}$/
        , '密码必须6到15位，且不能出现空格'
      ],
      confirmPass: function (value) {
        if ($('input[name=newpwd]').val() !== value)
          return '两次密码输入不一致！';
      }
    });
    form.on('submit(admin-save)', function (data) {
      $.ajax({
        url: "{:__url('system/admin/pass')}",
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'post',
        success: function (res) {
          if (res.code === 200) {
            hui_msg(res.msg, 1, function () {
              window.location.reload();
            });
          } else {
            hui_msg(res.msg, 2);
          }
        }
      })
      return false;
    });
  })
</script>
<script>
</script>
</body>
</html>
